package com.hliushi.serializable;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Serializable;

/**
 * @author llhuang10
 * @date 2021/10/27 16:04
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
class Student implements Serializable {
    private static final long serialVersionUID = -151444058958144466L;
    private String name;
}

public class Main {
    public static void main(String[] args) throws Exception {
        Kryo kryo = new Kryo();
        Output output = new Output(new FileOutputStream("student.db"));
        Student kirito = new Student("kirito");
        kryo.writeObject(output, kirito);
        output.close();
        Input input = new Input(new FileInputStream("student.db"));
        Student kiritoBak = kryo.readObject(input, Student.class);
        input.close();
        assert "kirito".equals(kiritoBak.getName());
    }
}
